﻿using MediatR;
using T.Basic.API.Appliction.Command.FuelCostCommand;
using T.Basic.Repository.BasicInterface;

namespace T.Basic.API.Appliction.CommandHandlers.FuelCostHanders
{
    /// <summary>
    /// 删除油费信息
    /// </summary>
    public class FuelCostDeleteAllCommandHandler : IRequestHandler<FuelCostDeleteAllCommand, int>
    {
        private readonly IFuelCostRepository _FuelCostrepository;
        public FuelCostDeleteAllCommandHandler(IFuelCostRepository fuelCostrepository)
        {
            _FuelCostrepository = fuelCostrepository;
        }
        public async Task<int> Handle(FuelCostDeleteAllCommand request, CancellationToken cancellationToken)
        {
            var ids = request.FuelCostIds;
            foreach (var item in ids)
            {
                var FuelCostDel=_FuelCostrepository.GetModelsAsync(item).Result;
                FuelCostDel.IsDeleted = true;
                
                await _FuelCostrepository.UpdateAsync(FuelCostDel);
            }
            return 1;
        }
    }
}
